/**
 * FileFind - ftp/shares indexing and search php engine
 * Module: persist-jpa20
 * Description: Persistence implementation with JPA 2.0
 * Copyright (c) 2003-2010 Rage Steel, www.gt2.ru
 */
package ru.ffind.persist.jpa20;

import ru.ffind.common.model.Host;
import ru.ffind.persist.jpa20.bean.AbstractEntityManagerFactoryBean;
import ru.ffind.persist.jpa20.model.DirImpl;
import ru.ffind.persist.jpa20.model.HostImpl;
import ru.ffind.persist.jpa20.service.EntryServiceImpl;
import ru.ffind.persist.jpa20.service.HostServiceImpl;

/**
 * Simple class to ensure that persistence is working.
 *
 * @author Rage Steel
 */
public class Runner {

    public static void main(String... args) {
    	AbstractEntityManagerFactoryBean entityManagerFactoryBean = new AbstractEntityManagerFactoryBean() {
		};

        HostServiceImpl hostService = new HostServiceImpl();
        hostService.setEntityManagerFactoryBean(entityManagerFactoryBean);

        EntryServiceImpl entryService = new EntryServiceImpl();
        entryService.setEntityManagerFactoryBean(entityManagerFactoryBean);

        for (Host host: hostService.findAll()) {
            System.out.println("Host: " + host);
            HostImpl hostImpl = (HostImpl) host;
            
            DirImpl rootDir = hostImpl.getRootDir();
            if (null == rootDir) {
            	System.out.println("Root directory does not set");
            } else {
            	System.out.println(entryService.findEntries(rootDir));
            }
        }
    }
}
